<?php
namespace BP\Sys;

use BP\En\EntityTree;

require_once("BP/En/Map.php");
class FrmTree extends EntityTree {
	public function getOrgNo () 
	{
		return $this->GetValStringByKey(FrmTreeAttr::$OrgNo);
	}
	public function setOrgNo ($value) // [String value]
	{
		$this->SetValByKey(FrmTreeAttr::$OrgNo, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($_No) // [String _No]
	{
		$me = new self();
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map("Sys_FormTree", "表单�?");
		$map->Java_SetCodeStruct("2");
		$map->Java_SetDepositaryOfEntity($Depositary->Application);
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->IndexField = FrmTreeAttr::$ParentNo;
		$map->AddTBStringPK(FrmTreeAttr::$No, NULL, "编号",  TRUE ,  TRUE , 1, 10, 20);
		$map->AddTBString(FrmTreeAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 100, 30);
		$map->AddTBString(FrmTreeAttr::$ParentNo, NULL, "父节点No",  FALSE ,  FALSE , 0, 100, 30);
		$map->AddTBString(FrmTreeAttr::$OrgNo, NULL, "组织编号",  FALSE ,  FALSE , 0, 100, 30);
		$map->AddTBInt(FrmTreeAttr::$Idx, 0, "Idx",  FALSE ,  FALSE );
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	protected function beforeDelete () 
	{
		if (!$DataType->IsNullOrEmpty($this->getNo()))
		{
			$this->DeleteChild($this->getNo());
		}
		return parent->beforeDelete();
	}
	protected function DeleteChild ($parentNo) // [String parentNo]
	{
		$formTrees = FrmTrees::constructor__();
		$formTrees->Retrieve(FrmTreeAttr::$ParentNo, $parentNo);
		foreach ($formTrees->ToJavaList() as $item) 		{
			$md = MapData::constructor__();
			$md->setFK_FormTree($item->getNo());
			$md->Delete();
			$this->DeleteChild($item->getNo());
		}
	}
	public function DoCreateSameLevelNode () 
	{
		$en = FrmTree::constructor__();
		$en->Copy($this);
		$en->setNo($String->valueOf(DBAccess->GenerOID()));
		$en->setName("新建节点");
		$en->Insert();
		return $en;
	}
	public function DoCreateSubNode () 
	{
		$en = FrmTree::constructor__();
		$en->Copy($this);
		$en->setNo($String->valueOf(DBAccess->GenerOID()));
		$en->setParentNo($this->getNo());
		$en->setName("新建节点");
		$en->Insert();
		return $en;
	}
}
?>
